home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / smaltalk / manchest.lha / MANCHESTER / manchester / 4.1 / OrderedDictionary.st < prev    next >
Text File  |  1993-07-24  |  20KB  |  616 lines

  1. "    NAME        OrderedDictionary
  2.     AUTHOR        Ifor Wyn Williams <ifor@uk.ac.man.cs>, ported to 4.1 by Mario Wolczko <mario@cs.man.ac.uk>
  3.     CONTRIBUTOR    Ifor Wyn Williams <ifor@uk.ac.man.cs>
  4.     FUNCTION     An ordered dictionary
  5.     ST-VERSIONS    4.1
  6.     PREREQUISITES    
  7.     CONFLICTS    
  8.     DISTRIBUTION    global
  9.     VERSION        1.3
  10.     DATE        26 Nov 1992
  11. SUMMARY        A dictionary that behaves like a SequenceableCollection
  12. (except that associations cannot be removed). 
  13. "!
  14.  
  15. 'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992 on 7 November 1992 at 3:34:49 pm'!
  16.  
  17.  
  18.  
  19. Dictionary variableSubclass: #OrderedDictionary
  20.     instanceVariableNames: 'order '
  21.     classVariableNames: ''
  22.     poolDictionaries: ''
  23.     category: 'Collections-Sequenceable'!
  24. OrderedDictionary comment:
  25. 'I am a subclass of Dictionary whose elements (associations) are ordered in a similar fashion to OrderedCollection.
  26.  
  27. I have one instance variable:
  28.  
  29. order <OrderedCollection>        OrderedCollection of keys reflecting the order of associations in the dictionary. '!
  30.  
  31.  
  32. !OrderedDictionary methodsFor: 'accessing'!
  33.  
  34. after: anAssociation 
  35.     "Return the association after anAssociation in the order. If anAssociation is the 
  36.     last association in the order, return nil. If anAssociation is 
  37.     not found, signal an error."
  38.  
  39.     1 to: order size - 1 do: [:index |
  40.         (self associationAt: (order at: index)) = anAssociation
  41.             ifTrue: [^self associationAt: (order at: index + 1)]].
  42.     (self associationAt: (order last)) = anAssociation
  43.         ifTrue: [^nil]
  44.         ifFalse: [^self keyNotFoundError: anAssociation key]!
  45.  
  46. associations
  47.     "Answer an OrderedCollection containing the receiver's associations."
  48.  
  49.     | anOrderedCollection |
  50.     anOrderedCollection := OrderedCollection new: order size.
  51.     order do: [:key | anOrderedCollection add: (self associationAt: key)].
  52.     ^anOrderedCollection!
  53.  
  54. at: key put: anObject 
  55.     "Set the value at key to be anObject. If key is not found, create a new 
  56.     entry for key and set its value to anObject. Answer anObject."
  57.  
  58.     (order includes: key)
  59.         ifFalse: [order add: key].
  60.     ^super at: key put: anObject!
  61.  
  62. atAll: anInterval put: anObject 
  63.     "Put anObject into the value field of every association specified by the interval."
  64.  
  65.     anInterval do: [:index | self at: (order at: index) put: anObject]!
  66.  
  67. atAllPut: anObject 
  68.     "Put anObject into the value field of every association in the dictionary."
  69.  
  70.     order do: [:key | self at: key put: anObject]!
  71.  
  72. before: anAssociation 
  73.     "Return the association before anAssociation in the order. If anAssociation is the 
  74.     first association in the order, return the undefined object. If anAssociation is 
  75.     not found, invoke an error notifier"
  76.  
  77.     2 to: order size do: [:index |
  78.         (self associationAt: (order at: index)) = anAssociation
  79.             ifTrue: [^self associationAt: (order at: index - 1)]].
  80.     (self associationAt: order first) = anAssociation
  81.         ifTrue: [^nil]
  82.         ifFalse: [^self keyNotFoundError: anAssociation key]!
  83.  
  84. first
  85.     "Answer the first association of the receiver.  Provide an error 
  86.     notification if the receiver contains no elements."
  87.  
  88.     order emptyCheck.
  89.     ^self associationAt: (order first)!
  90.  
  91. keys
  92.     "Answer a OrderedCollection containing the receiver's keys."
  93.  
  94.     ^order copy!
  95.  
  96. last
  97.     "Answer the last association of the receiver. Provide an error 
  98.     notification if the receiver contains no elements."
  99.  
  100.     order emptyCheck.
  101.     ^self associationAt: (order last)!
  102.  
  103. order
  104.     ^order!
  105.  
  106. values
  107.     "Answer a OrderedCollection containing the receiver's values."
  108.  
  109.     | anOrderedCollection |
  110.     anOrderedCollection := OrderedCollection new: order size.
  111.     order do: [:key | anOrderedCollection add: (self at: key)].
  112.     ^anOrderedCollection! !
  113.  
  114. !OrderedDictionary methodsFor: 'testing'!
  115.  
  116. occurrencesOfKey: aKey 
  117.     "Answer how many of the dictionary's keys are equal to aKey."
  118.  
  119.     | count |
  120.     count := 0.
  121.     1 to: self size do: [:index | aKey = (order at: index) ifTrue: [count := count + 1]].
  122.     ^count!
  123.  
  124. occurrencesOfValue: aValue 
  125.     "Answer how many of the dictionary's values are equal to aValue."
  126.  
  127.     | count |
  128.     count := 0.
  129.     1 to: self size do: [:index | aValue = (self at: (order at: index)) ifTrue: [count := count + 1]].
  130.     ^count! !
  131.  
  132. !OrderedDictionary methodsFor: 'adding'!
  133.  
  134. add: anAssociation 
  135.     "Add anAssociation to the dictionary."
  136.  
  137.     | key |
  138.     key := anAssociation key.
  139.     (super includesKey: key)
  140.         ifFalse: [order add: key].
  141.     ^super add: anAssociation!
  142.  
  143. add: anAssociation after: oldAssociation 
  144.     "Add the argument, anAssociation, as an element of the dictionary.
  145.     Put it in the position just after oldAssociation. Answer anAssociation."
  146.  
  147.     | index |
  148.     index := self indexOfAssociation: oldAssociation ifAbsent: [self keyNotFoundError: oldAssociation key].
  149.     self removeFromOrder: anAssociation key.
  150.     order add: anAssociation key after: (order at: index).
  151.     super add: anAssociation.
  152.     ^anAssociation!
  153.  
  154. add: anAssociation before: oldAssociation 
  155.     "Add the argument, anAssociation, as an element of the dictionary. Put it 
  156.     in the position just before oldAssociation. Answer anAssociation."
  157.  
  158.     | index |
  159.     index := self indexOfAssociation: oldAssociation ifAbsent: [self keyNotFoundError: oldAssociation key].
  160.     self removeFromOrder: anAssociation key.
  161.     order add: anAssociation key before: (order at: index).
  162.     super add: anAssociation.
  163.     ^anAssociation!
  164.  
  165. add: anAssociation beforeIndex: spot 
  166.     "Add the argument, anAssociation, as an element of the receiver.  Put it
  167.     in the position just before the indexed position spot.  Answer anAssociation."
  168.  
  169.     self removeFromOrder: anAssociation key.
  170.     order add: anAssociation key beforeIndex: spot. 
  171.     ^super add: anAssociation!
  172.  
  173. addAll: aCollectionOfAssociations 
  174.     "Add each element of aCollectionOfAssociations at my end."
  175.  
  176.     (aCollectionOfAssociations respondsTo: #associationsDo:)
  177.         ifTrue: [aCollectionOfAssociations associationsDo: [:elems | self add: elems]]
  178.         ifFalse: [aCollectionOfAssociations do: [:elems | self add: elems]].
  179.     ^aCollectionOfAssociations!
  180.  
  181. addAllFirst: anOrderedCollectionOfAssociations 
  182.     "Add each element of anOrderedCollectionOfAssociations at the beginning of the receiver."
  183.  
  184.     anOrderedCollectionOfAssociations reverseDo: [:each | self addFirst: each].
  185.     ^anOrderedCollectionOfAssociations!
  186.  
  187. addAllLast: anOrderedCollectionOfAssociations 
  188.     "Add each element of anOrderedCollectionOfAssociations at the end of the receiver."
  189.     anOrderedCollectionOfAssociations do: [:each | self addLast: each].
  190.     ^anOrderedCollectionOfAssociations!
  191.  
  192. addFirst: anAssociation 
  193.     "Add anAssociation to the beginning of the receiver.  Answer anAssociation."
  194.  
  195.     self removeFromOrder: anAssociation key.
  196.     order addFirst: anAssociation key.
  197.     ^super add: anAssociation.!
  198.  
  199. addLast: anAssociation 
  200.     "Add anAssociation to the end of the receiver.  Answer anAssociation."
  201.     self removeFromOrder: anAssociation key.
  202.     order addLast: anAssociation key.
  203.     ^super add: anAssociation.!
  204.  
  205. grow
  206.     "Increase the number of elements in the dictionary"
  207.  
  208.     | newSelf |
  209.     newSelf := (self class) new: (self basicSize + self growSize).
  210.     order do: [:key | newSelf add: (self associationAt: key)].
  211.     self become: newSelf! !
  212.  
  213. !OrderedDictionary methodsFor: 'copying'!
  214.  
  215. copyEmpty
  216.     "Answer a copy of the receiver that contains no elements."
  217.  
  218.     ^(self class) new: 10!
  219.  
  220. copyEmpty: aSize
  221.     "Answer a copy of the receiver that contains no elements."
  222.  
  223.     ^(self class) new: aSize!
  224.  
  225. copyFrom: startIndex to: endIndex 
  226.     "Answer a copy of the receiver that contains elements from 
  227.     position startIndex to endIndex."
  228.  
  229.     | newDict |
  230.     endIndex < startIndex ifTrue: [^self copyEmpty].
  231.     (startIndex < 1 or: [endIndex > order size])
  232.         ifTrue: [^self error: 'Index out of bounds'].
  233.     newDict := self copyEmpty: endIndex - startIndex + 1.
  234.     startIndex to: endIndex do: [:index | newDict add: (self associationAt: (order at: index))].
  235.     ^newDict!
  236.  
  237. copyWith: anAssociation 
  238.     "Answer a copy of the dictionary that is 1 bigger than the receiver and 
  239.     includes the argument, anAssociation, at the end."
  240.  
  241.     | newDict |
  242.     newDict := self copy.
  243.     newDict add: anAssociation.
  244.     ^newDict!
  245.  
  246. copyWithout: anAssociation 
  247.     "Answer a copy of the dictionary that is 1 smaller than the receiver and does 
  248.     not includes the argument, anAssociation"
  249.  
  250.     | newDict |
  251.     newDict := OrderedDictionary new: order size - 1.
  252.     self associationsDo: [:assoc | anAssociation = assoc ifFalse: [newDict add: assoc]]! !
  253.  
  254. !OrderedDictionary methodsFor: 'dictionary removing'!
  255.  
  256. removeAssociation: anAssociation ifAbsent: anExceptionBlock 
  257.     "Remove the key and value association, anAssociation, from the 
  258.     receiver.  If not found, answer the result of evaluating 
  259.     anExceptionBlock, otherwise answer anAssociation."
  260.  
  261.     self removeFromOrder: anAssociation key.
  262.     ^super removeAssociation: anAssociation ifAbsent: anExceptionBlock!
  263.  
  264. removeKey: key ifAbsent: aBlock 
  265.     "Remove key from the receiver.  If key is not in the receiver, 
  266.     answer the result of evaluating aBlock.  Otherwise, answer the value 
  267.     associated with key."
  268.  
  269.     self removeFromOrder: key.
  270.     ^super removeKey: key ifAbsent: aBlock! !
  271.  
  272. !OrderedDictionary methodsFor: 'enumerating'!
  273.  
  274. associationsDo: aBlock 
  275.     "Evaluate aBlock for each of the dictionary's associations."
  276.  
  277.     order do: [:key | aBlock value: (self associationAt: key)]!
  278.  
  279. associationsDo: aBlock from: firstIndex to: secondIndex 
  280.     "Evaluate aBlock with each of the dictionary's associations from index 
  281.     firstIndex to index secondIndex as the argument."
  282.  
  283.     firstIndex to: secondIndex do: [:index | aBlock value: (self associationAt: (order at: index))]!
  284.  
  285. collect: aBlock 
  286.     "Evaluate aBlock with each of the associations of the dictionary as the 
  287.     argument. The block should return an association which will be added to the 
  288.     new OrderedDictionary"
  289.  
  290.     | newDict |
  291.     newDict := OrderedDictionary new.
  292.     1 to: order size do: [:index | newDict add: (aBlock value: (self associationAt: (order at: index)))].
  293.     ^newDict!
  294.  
  295. do: aBlock 
  296.     "Evaluate aBlock for each of the dictionary's values."
  297.  
  298.     order do: [:key | aBlock value: (self at: key)]!
  299.  
  300. do: aBlock from: firstIndex to: secondIndex 
  301.     "Evaluate aBlock with each of the dictionary's associations from index 
  302.     firstIndex to index secondIndex as the argument."
  303.  
  304.     firstIndex to: secondIndex do: [:index | aBlock value: (self at: (order at: index))]!
  305.  
  306. findFirst: aBlock 
  307.     "Answer the index of the first association in the dictionary for which aBlock 
  308.     evaluates to true.  If the block never evaluates to true, return 0"
  309.  
  310.     1 to: order size do: [:index |
  311.         (aBlock value: (self associationAt: (order at: index)))
  312.             ifTrue: [^index]].
  313.     ^0!
  314.  
  315. findLast: aBlock 
  316.     "Evaluate aBlock for the each of the associations in reverse order.  Return the index
  317.     of the first that evaluates to true.  If the block never evaluates to true, return 0"
  318.  
  319.     order size
  320.         to: 1
  321.         by: -1
  322.         do: [:index | 
  323.                 (aBlock value: (self associationAt: (order at: index)))
  324.                     ifTrue: [^index]].
  325.     ^0!
  326.  
  327. reverse
  328.     "Answer with a new OrderedDictionary with its associations in reverse order."
  329.  
  330.     | newDict|
  331.     newDict := OrderedDictionary new.
  332.     order size
  333.         to: 1
  334.         by: -1
  335.         do: 
  336.             [:index || key |
  337.             key := order at: index.
  338.             newDict at: key put: (self at: key)].
  339.     ^newDict!
  340.  
  341. reverseDo: aBlock 
  342.     "Evaluate aBlock with each of the dictionary's associations as the argument, 
  343.     starting with the last element and taking each in sequence up to the first."
  344.  
  345.     order size
  346.         to: 1
  347.         by: -1
  348.         do: [:index | aBlock value: (self associationAt: (order at: index))]!
  349.  
  350. select: aBlock 
  351.     "Evaluate aBlock with each of the dictionary's associations as the argument. 
  352.     Collect into a new OrderedDictionary only those associations for which 
  353.     aBlock evaluates to true. Answer the new OrderedDictionary."
  354.  
  355.     | newDict |
  356.     newDict := OrderedDictionary new.
  357.     1 to: order size do: 
  358.         [:index || key |
  359.         key := order at: index.
  360.         (aBlock value: (self associationAt: key))
  361.             ifTrue: [newDict add: (self associationAt: key)]].
  362.     ^newDict! !
  363.  
  364. !OrderedDictionary methodsFor: 'accessing index'!
  365.  
  366. identityIndexOfAssociation: anAssociation 
  367.     "Answer the identity index of anAssociation within the receiver. If the receiver 
  368.     does not contain anAssociation, answer 0."
  369.  
  370.     ^self identityIndexOfAssociation: anAssociation ifAbsent: [0]!
  371.  
  372. identityIndexOfAssociation: anAssociation ifAbsent: exceptionBlock 
  373.     "Answer the identity index of anAssociation within the receiver. If the receiver 
  374.     does not contain anAssociation, answer the result of evaluating the exceptionBlock."
  375.  
  376.     1 to: order size do: [:i |
  377.         (self associationAt: (order at: i)) == anAssociation ifTrue: [^i]].
  378.     ^exceptionBlock value!
  379.  
  380. identityIndexOfKey: aKey 
  381.     "Answer the identity index of aKey within the receiver. If the receiver 
  382.     does not contain aKey, answer 0."
  383.  
  384.     ^self identityIndexOfKey: aKey ifAbsent: [0]!
  385.  
  386. identityIndexOfKey: aKey ifAbsent: exceptionBlock 
  387.     "Answer the identity index of aKey within the receiver.  If the receiver does
  388.     not contain aKey, answer the result of evaluating the exceptionBlock."
  389.  
  390.     1 to: order size do: [:i |
  391.         (order at: i) == aKey ifTrue: [^i]].
  392.     ^exceptionBlock value!
  393.  
  394. identityIndexOfValue: aValue 
  395.     "Answer the identity index of aValue within the receiver. If the receiver 
  396.     does not contain aValue, answer 0."
  397.  
  398.     ^self identityIndexOfValue: aValue ifAbsent: [0]!
  399.  
  400. identityIndexOfValue: aValue ifAbsent: exceptionBlock 
  401.     "Answer the identity index of aValue within the receiver. If the receiver 
  402.     does not contain aValue, answer the result of evaluating the exceptionBlock."
  403.  
  404.     1 to: order size do: [:i |
  405.         (self at: (order at: i)) == aValue ifTrue: [^i]].
  406.     ^exceptionBlock value!
  407.  
  408. indexOfAssociation: anAssociation 
  409.     "Answer the index of anAssociation within the receiver. If the receiver does 
  410.     not contain anAssociation, answer 0."
  411.  
  412.     ^self indexOfAssociation: anAssociation ifAbsent: [0]!
  413.  
  414. indexOfAssociation: anAssociation ifAbsent: exceptionBlock 
  415.     "Answer the identity index of anAssociation within the receiver. If the receiver 
  416.     does not contain anAssociation, answer the result of evaluating the exceptionBlock."
  417.  
  418.     1 to: order size do: [:i |
  419.         (self associationAt: (order at: i)) = anAssociation ifTrue: [^i]].
  420.     ^exceptionBlock value!
  421.  
  422. indexOfKey: aKey 
  423.     "Answer the index of aKey within the receiver. If the receiver does 
  424.     not contain aKey, answer 0."
  425.  
  426.     ^self indexOfKey: aKey ifAbsent: [0]!
  427.  
  428. indexOfKey: aKey ifAbsent: exceptionBlock 
  429.     "Answer the identity index of aKey within the receiver.  If the receiver does
  430.     not contain aKey, answer the result of evaluating the exceptionBlock."
  431.  
  432.     1 to: order size do: [:i |
  433.         (order at: i) = aKey ifTrue: [^i]].
  434.     ^exceptionBlock value!
  435.  
  436. indexOfValue: aValue 
  437.     "Answer the index of aValue within the receiver. If the receiver does 
  438.     not contain aValue, answer 0."
  439.  
  440.     ^self indexOfValue: aValue ifAbsent: [0]!
  441.  
  442. indexOfValue: aValue ifAbsent: exceptionBlock 
  443.     "Answer the identity index of aValue within the receiver. If the receiver 
  444.     does not contain aValue, answer the result of evaluating the exceptionBlock."
  445.  
  446.     1 to: order size do: [:i |
  447.         (self at: (order at: i)) = aValue ifTrue: [^i]].
  448.     ^exceptionBlock value!
  449.  
  450. nextIndexOfAssociation: aAssociation from: startIndex to: stopIndex 
  451.     "Answer the next index of aAssociation within the receiver between startIndex 
  452.     and stopIndex. If the receiver does not contain aAssociation, answer nil"
  453.  
  454.     startIndex to: stopIndex do: [:i |
  455.         (self associationAt: (order at: i)) = aAssociation ifTrue: [^i]].
  456.     ^nil!
  457.  
  458. nextIndexOfKey: aKey from: startIndex to: stopIndex 
  459.     "Answer the next index of aKey within the receiver between startIndex and 
  460.     stopIndex.  If the receiver does not contain aKey, answer nil"
  461.  
  462.     startIndex to: stopIndex do: [:i |
  463.         (order at: i) = aKey ifTrue: [^i]].
  464.     ^nil!
  465.  
  466. nextIndexOfValue: aValue from: startIndex to: stopIndex 
  467.     "Answer the next index of aValue within the receiver between startIndex and 
  468.     stopIndex. If the receiver does not contain aValue, answer nil"
  469.  
  470.     startIndex to: stopIndex do: [:i |
  471.         (self at: (order at: i)) = aValue ifTrue: [^i]].
  472.     ^nil!
  473.  
  474. prevIndexOfAssociation: aAssociation from: startIndex to: stopIndex 
  475.     "Answer the previous index of aAssociation within the receiver between startIndex 
  476.     and stopIndex working backwards through the receiver. If the receiver does 
  477.     not contain aAssociation, answer nil"
  478.  
  479.     startIndex
  480.         to: stopIndex
  481.         by: -1
  482.         do: [:i |
  483.             (self associationAt: (order at: i)) = aAssociation ifTrue: [^i]].
  484.     ^nil!
  485.  
  486. prevIndexOfKey: aKey from: startIndex to: stopIndex 
  487.     "Answer the previous index of aKey within the receiver between startIndex and 
  488.     stopIndex working backwards through the receiver. If the receiver does not 
  489.     contain aKey, answer nil"
  490.  
  491.     startIndex
  492.         to: stopIndex
  493.         by: -1
  494.         do: [:i | (order at: i) = aKey ifTrue: [^i]].
  495.     ^nil!
  496.  
  497. prevIndexOfValue: aValue from: startIndex to: stopIndex 
  498.     "Answer the previous index of aValue within the receiver between startIndex 
  499.     and stopIndex working backwards through the receiver. If the receiver does 
  500.     not contain aValue, answer nil"
  501.  
  502.     startIndex
  503.         to: stopIndex
  504.         by: -1
  505.         do: [:i | (self at: (order at: i)) = aValue ifTrue: [^i]].
  506.     ^nil! !
  507.  
  508. !OrderedDictionary methodsFor: 'user interface'!
  509.  
  510. inspect
  511.     "Create and schedule a DictionaryInspector in which the user can examine the
  512.     receiver's variables."
  513.  
  514.     Cursor wait showWhile: [Inspector open: (OrderedDictionaryInspector inspect: self)]! !
  515.  
  516. !OrderedDictionary methodsFor: 'private'!
  517.  
  518. initialize
  519.     order := OrderedCollection new!
  520.  
  521. removeFromOrder: aKey 
  522.     order remove: aKey ifAbsent: []! !
  523. "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
  524.  
  525. OrderedDictionary class
  526.     instanceVariableNames: ''!
  527.  
  528.  
  529. !OrderedDictionary class methodsFor: 'test'!
  530.  
  531. test1
  532.     "OrderedDictionary test1"
  533.     | selectTest o3  o5 a1 a2 a3 a4 a6 d1 col1 col2 col3 d2 b1 b2 b3 b4 b5 c1 c2 c3 c4 c5 e1 e2 e3 e4 e5 |
  534.     d1 := OrderedDictionary new.
  535.     d1 at: 1 put: 'one'.
  536.     d1 at: 2 put: 'two'.
  537.     d1 at: 3 put: 'three'.
  538.     d1 at: 4 put: 'four'.
  539.     d1 at: 5 put: 'five'.
  540.     d1 at: 6 put: 'six'.
  541.     d1 at: 7 put: 'seven'.
  542.     d2 := OrderedDictionary new.
  543.     d2 at: 11 put: 'eleven'.
  544.     d2 at: 12 put: 'twelve'.
  545.     d2 at: 13 put: 'thirteen'.
  546.     d2 at: 14 put: 'fourteen'.
  547.     d2 at: 15 put: 'fifteen'.
  548.     d2 at: 16 put: 'sixteen'.
  549.     d2 at: 17 put: 'seventeen'.
  550.     b1 := Association key: 31 value: 'threeOne'.
  551.     b2 := Association key: 32 value: 'threeTwo'.
  552.     b3 := Association key: 33 value: 'threeThree'.
  553.     b4 := Association key: 34 value: 'threeFour'.
  554.     b5 := Association key: 35 value: 'threeFive'.
  555.     c1 := Association key: 41 value: 'fourOne'.
  556.     c2 := Association key: 42 value: 'fourTwo'.
  557.     c3 := Association key: 43 value: 'fourThree'.
  558.     c4 := Association key: 44 value: 'fourFour'.
  559.     c5 := Association key: 45 value: 'fourFive'.
  560.     e1 := Association key: 51 value: 'fiveOne'.
  561.     e2 := Association key: 52 value: 'fiveTwo'.
  562.     e3 := Association key: 53 value: 'fiveThree'.
  563.     e4 := Association key: 54 value: 'fiveFour'.
  564.     e5 := Association key: 55 value: 'fiveFive'.
  565.     col1 := OrderedCollection new.
  566.     col1 add: b1; add: b2; add: b3; add: b4; add: b5.
  567.     col2 := OrderedCollection new.
  568.     col2 add: c1; add: c2; add: c3; add: c4; add: c5.
  569.     col3 := OrderedCollection new.
  570.     col3 add: e1; add: e2; add: e3; add: e4; add: e5.
  571.     o3 := Association key: 3 value: 'three'.
  572.     o5 := Association key: 5 value: 'five'.
  573.     a1 := Association key: 21 value: 'twentyOne'.
  574.     a2 := Association key: 22 value: 'twentyTwo'.
  575.     a3 := Association key: 23 value: 'twentyThree'.
  576.     a4 := Association key: 24 value: 'twentyFour'.
  577.     a6 := Association key: 21 value: 'twentyOneTwice'.
  578.     d1 add: a1 after: o3.
  579.     d1 add: a2 after: o5.
  580.     d1 add: a3 before: a2.
  581.     d1 add: a4 beforeIndex: 4.
  582.     d1 add: a6 beforeIndex: 4.
  583.     d1 addAll: col1.
  584.     d1 addAllFirst: col2 .
  585.     d1 addAllLast: col3.
  586.     "collectTest := d1 collect: [:assoc| Association key: (assoc key) value: 42]."
  587.     selectTest:= d1 select: [:assoc|  (assoc key) > 20 ].
  588.     selectTest := selectTest reverse.
  589.     (d1 atAll: (Interval from: 5 to: 10) put: 42 ).
  590.     (d1 copyWithout: a6 ) inspect
  591.     " OrderedDictionary (41->'fourOne' 42->'fourTwo' 43->'fourThree' 44->'fourFour' 45->42 1->42 2->42 3->42 21->42 24->42 4->'four' 5->'five' 23->'twentyThree' 22->'twentyTwo' 6->'six' 7->'seven' 31->'threeOne' 32->'threeTwo' 33->'threeThree' 34->'threeFour' 35->'threeFive' 51->'fiveOne' 52->'fiveTwo' 53->'fiveThree' 54->'fiveFour' 55->'fiveFive' )"! !
  592.  
  593. !OrderedDictionary class methodsFor: 'instance creation'!
  594.  
  595. new
  596.     ^super new initialize!
  597.  
  598. new: anInteger
  599.     ^(super new: anInteger) initialize! !
  600.  
  601.  
  602. DictionaryInspector subclass: #OrderedDictionaryInspector
  603.     instanceVariableNames: ''
  604.     classVariableNames: ''
  605.     poolDictionaries: ''
  606.     category: 'Tools-Inspector'!
  607.  
  608.  
  609. !OrderedDictionaryInspector methodsFor: 'field list'!
  610.  
  611. fieldList
  612.     "Answer a collection of the keys of the inspected dictionary."
  613.  
  614.     ^object order! !
  615.  
  616.